<template>
	<div class="entry_container">
		<k-header headTitle="找回密码" goBack="true"></k-header>
		<div :class="headIos?'archieve_container-ios':'entry_content'">
			<img src="../../assets/img/user/forget.png" style="width:81%;margin:15px auto 0px;display: block;"/>
			<input class="entry-phone _input" placeholder="请输入手机号码" v-model="mobile" maxlength="11">
			<div class="entry_pass">
				<input type="text" class="entry-pass _input" placeholder="请输入验证码" v-model="code" maxlength="4">
				<button @click="kedian" class="kedian">{{data}}</button>
			</div>
			<toast v-model="showPositionValue" type="text" width="100%" :time="1800" is-show-mask :text="message" position="bottom"></toast>
			<button class="setpass" :disabled="diss" @click="goNext">下一步</button>
		</div>
	</div>
</template>

<script>
	import kHeader from '../common/head';
	import util from '../../libs/util';
	import { Toast} from 'vux';
	export default {
         data () {
            return {
            	data: '发送验证码',
            	time: 60,
            	mobile:'',
            	showPositionValue:false,
            	message:'请输入正确的手机号',
            	diss:false,
							code:'',
							headIos:false
            }
        },
        components: {
        	kHeader,
        	Toast
        },
        methods: {
        	kedian : function(){
        		var url ='/lblsapp-h5/v2/account/sendSMS.json';
        		let data={mobile:this.mobile,source:'RESETPWD'}
        		var regtel = /^(0|86|17951)?(13[0-9]|15[012356789]|17[01356789]|18[0-9]|14[579])[0-9]{8}$/;
        		let istel = regtel.test(this.mobile);
        		if(istel){
        			var that = this;
	        		this.data = 60 + 's';
	        		var iTime = setInterval(function(){
	        			that.time--;
	        			that.data = that.time + 's';
	        			if(that.time ==0){
	        				that.data = '发送验证码';
	        				that.time = 60;
	        				clearInterval(iTime);
	        			}
	        		},1000);
	        		util.ajax.post(url, data).then(function(data){
	        			// console.log(data);
	        		 	if(data.data.code==='0'){
	        		 	}else{
	        		 		that.message = data.data.res.msg;
	        		 		that.showPositionValue=true;
	        		 	}
	        		}).catch(function(error){
	        			console.log(error);
	        		})
        		}else{
        			this.message='请输入正确的手机号';
        			this.showPositionValue=true;
        		}
        	},
        	goNext(){
        		this.diss=true;
        		var url='/lblsapp-h5/v2/account/resetPersonal.json';
        		let data={mobile:this.mobile,smsCode:this.code};
        		var regtel = /^(0|86|17951)?(13[0-9]|15[012356789]|17[01356789]|18[0-9]|14[579])[0-9]{8}$/;
        		let istel = regtel.test(this.mobile);
        		if(istel){
        			var that = this;
        			util.ajax.post(url, data).then(function(data){
        				// console.log(data);
        				if(data.data.code==='0'){
        					that.$cookie.set('uuidCode',data.data.res.msg,0.05);
        					that.$router.push({path:'/setpass'})
        				}else{
        					that.message = data.data.res.msg;
	        		 		that.showPositionValue=true;
	        		 		that.diss=false;
        				}
        			}).catch(function(error){
	        			console.log(error);
	        			that.diss=false;
	        		})
        		}else{
        			this.message='请输入正确的手机号';
        			this.showPositionValue=true;
        		}
        	}
        },
        created(){
					if (window.navigator.userAgent.indexOf('LBLSIOS') > -1) {
						this.headIos = true
					} else {
						this.headIos = false
					};
        	this.mobile = this.$route.query.mobile;
        },
    }
</script>

<style>
		.entry_container{
     	/* padding-top: 45px; */
    }
    .entry_content{
    	padding: 0 8%;
    	position: relative;
    }
    .entry_pass{
    	position: relative;
    }
    .kedian{
    	z-index: 9;
	    position: absolute;
	    top: 13px;
	    right: 11.7%;
		font-size: 1.4rem;
		color: #F89721;
		letter-spacing: 0;
		background: none;
    	border: none;
    }
    .setpass{
    	display: block;
    	margin-top: 55px;
    	background: #F89721;
		border-radius: 2px;
    	width: 100%;
    	text-align: center;
    	height: 42px;
    	line-height: 42px;
    	font-size: 14px;
		color: #FFF;
		letter-spacing: 0;
		border: none;
    }
</style>